let dataSource = require('../service/dataSource');
let sql = require('../service/booksql');

class Book {

    hello(req, res, next) {
        console.log('HELLO......');
        res.render('book', {title: 'BOOK'});
    }

    getAll(req, res, next) {
        console.log('HELLO......');
        dataSource.query(sql.getAll, function (err, result) {
            dataSource.jsonWrite(res, result);
        })}

    findById(req, res, next) {
        console.log('findById.');
        let bookId = req.params.bookId;
        dataSource.query(sql.findById(bookId), function (err, result) {
            console.log(result[0]);
            dataSource.jsonWrite(res, result);
        })
    }
}

module.exports = new Book();